package testcase;

import information.Line;
import information.Pier;

/**
 * @author Louis Luk(52591063), Peter Au Yeung(52582030), Sam Cheung(52603693)
 * @version for Pier.java v2.0.0
 * @since 27-02-2013
 */

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

/**
 * @author Louis Luk(52591063), Peter Au Yeung(52582030), Sam Cheung(52603693)
 * @version for Pier.java v2.3.5 refactor by Rigsby Chi(52584035)
 * @since 08-04-2013
 */
public class PierTest {
	private Pier tempPier;
	private int numberOfLine;

	@Before
	public void setUp() throws Exception {
		tempPier = new Pier(3);

		tempPier.addLine(new Line(1700, 35, 2, 120, 1));
		tempPier.addLine(new Line(1345, 15, 4, 60, 2));
		tempPier.addLine(new Line(1900, 10, 3, 40, 3));

		numberOfLine = 3;
	}

	private int[] tempLine0 = { 1700, 35, 2, 120, 1 };
	private int[] tempLine1 = { 1345, 15, 4, 60, 2 };
	private int[] tempLine2 = { 1900, 10, 3, 40, 3 };

	// TESTS for getNumberOfLines()
	@Test
	public void testGetNumberOfLines() {
		assertEquals(tempPier.getNumberOfLines(), numberOfLine);
	}

	@Test
	// after 1 line is added
	public void testGetNumberOfLines_1Line() {
		tempPier.addLine(new Line(1000, 30, 6, 40, 1));
		numberOfLine++;

		assertEquals(tempPier.getNumberOfLines(), numberOfLine);
	}

	@Test
	// after 2 line is added
	public void testGetNumberOfLines_2Line() {
		tempPier.addLine(new Line(1430, 20, 3, 90, 3));
		numberOfLine++;
		tempPier.addLine(new Line(300, 60, 5, 30, 2));
		numberOfLine++;

		assertEquals(tempPier.getNumberOfLines(), numberOfLine);
	}

	// TESTS for getLine(int)
	@Test
	// getting Line 0 in the List
	public void testGetLine_0() {
		assertArrayEquals(tempPier.getLine(0), tempLine0);
	}

	@Test
	// getting Line 1 in the List
	public void testGetLine_1() {
		assertArrayEquals(tempPier.getLine(1), tempLine1);
	}

	@Test
	// Test for getting Line 2 in the List
	public void testGetLine_2() {
		assertArrayEquals(tempPier.getLine(2), tempLine2);
	}

	// TESTS for getSizeOfPier()
	@Test
	// getting the size of the small pier
	public void testGetSize_smallPier() {
		Pier testPier = new Pier(1);

		assertEquals(testPier.getSizeOfPier(), 1);
	}

	@Test
	// getting the size of the middle pier
	public void testGetSize_middlePier() {
		Pier testPier = new Pier(2);

		assertEquals(testPier.getSizeOfPier(), 2);
	}

	@Test
	// getting the size of the large pier
	public void testGetSize_largePier() {
		Pier testPier = new Pier(3);

		assertEquals(testPier.getSizeOfPier(), 3);
	}

	// TEST for getPriority()
	@Test
	public void testGetPriority() {
		Pier testPier = new Pier(2);

		assertEquals((int) testPier.getPriority(), 2);
	}

	// TEST for dropLine(int)
	@Test
	public void testDropLine() {
		Pier testPier = new Pier(3);
		testPier.addLine(new Line(1, 2, 3, 4, 5));
		testPier.addLine(new Line(2, 4, 6, 8, 10));
		testPier.addLine(new Line(3, 6, 9, 12, 15));
		testPier.dropLine(1);
		int[] testData = testPier.getLine(1);

		assertEquals(3, testData[0]);
		assertEquals(6, testData[1]);
		assertEquals(9, testData[2]);
		assertEquals(12, testData[3]);
		assertEquals(15, testData[4]);
	}

	// TESTS for isSameLine(Line, int)
	@Test
	public void testIsSameLine_equal() {
		Pier testPier = new Pier(1);
		testPier.addLine(new Line(1, 2, 3, 4, 5));
		assertEquals(true, testPier.isSameLine(new Line(1, 2, 3, 4, 5), 0));
	}

	@Test
	public void testIsSameLine_unequal() {
		Pier testPier = new Pier(1);
		testPier.addLine(new Line(1, 2, 3, 4, 5));
		assertEquals(false, testPier.isSameLine(new Line(1, 1, 1, 1, 1), 0));
	}

}
